#pragma once

#include <string>
#include <stdarg.h>
#include <cstdio>
#include <time.h>
#define DEBUG   0
#define NORMAL  1
#define WARNING 2
#define ERROR   3
#define FATAL   4
#define LOGFILE "./threadpool.log"
const char* gLevelMap[] = {
    "DEBUG",
    "NORMAL",
    "WARNING",
    "ERROR",
    "FATAL"
};

// 完整的日志功能，至少：日志等级 时间 支持用户自定义(日志内容，文件行，文件名下· )
void logMessage(int level,const char* format,...)
{
#ifndef DEBUG_SHOW
    if(level == DEBUG) return;
#endif
    char stdBuffer[1024];
    time_t timestamp = time(nullptr);
    snprintf(stdBuffer,sizeof stdBuffer,"[%s] [%ld]",gLevelMap[level],timestamp);
    char logBuffer[1024];
    va_list args;
    va_start(args,format);
    // vprintf(format,args);
    vsnprintf(logBuffer,sizeof logBuffer,format,args);
    va_end(args);
    // FILE *fp = fopen(LOGFILE, "a");
    printf("%s%s\n", stdBuffer, logBuffer);
    // fprintf(fp, "%s%s\n", stdBuffer, logBuffer);
    // fclose(fp);

}